package com.xcity.pomelo.response;

import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.List;

import com.xcity.game.pet.Pet;
import com.xcity.game.pet.PetSkill;
import com.xcity.game.pet.template.PetSkillLevelUpTemplate;

import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;
import naga.x.util.NumberUtils;

@PomeloMessage(type = Message.Type.RESPONSE)
public class PetInfoResponse extends EmptyPetResponse {
	
	private String name;
	private String icon;
	private int level;
	private int exp;
	private byte sex;
	private byte state; // 0:休息, 1:工作
	private String type;
	private String animation;
	private int generation; // 代数
	private int spirit; // 当前精神值
	private int spiritMax; // 最大精神值
	private int food; // 消耗粮食
	private int washCD; // 洗澡cd(秒)
	private int playCD; // 玩耍cd(秒)
	private int washCost; // 洗澡消耗现金
	private List<Skill> skills;
	
	public static class Skill {
		private int id;
		private String name;
		private String desc;
		private String nextLvlDesc;
		public Skill(PetSkill skill) {
			this.id = skill.getId();
			this.name = skill.getTemplate().getName();
			this.desc = skill.getTemplate().getDesc();
			this.nextLvlDesc = this.desc;
			if (this.desc.contains("{0")) {
				PetSkillLevelUpTemplate temp = skill.getLevelUpTemplate();
				this.desc = MessageFormat.format(this.desc, NumberUtils.ints2integers(temp.getValue()));
			}
			if (skill.getLevel() < skill.getMaxLevel()) {
				if (this.nextLvlDesc.contains("{0")) {
					PetSkillLevelUpTemplate temp = skill.getTemplate().getLevelUpTemplate(skill.getLevel() + 1);
					this.nextLvlDesc = MessageFormat.format(this.nextLvlDesc, NumberUtils.ints2integers(temp.getValue()));
				}
			} else {
				this.nextLvlDesc = "";
			}
		}
		public int getId() {
			return id;
		}
		public void setId(int id) {
			this.id = id;
		}
		public String getName() {
			return name;
		}
		public void setName(String name) {
			this.name = name;
		}
		public String getDesc() {
			return desc;
		}
		public void setDesc(String desc) {
			this.desc = desc;
		}
		public String getNextLvlDesc() {
			return nextLvlDesc;
		}
		public void setNextLvlDesc(String nextLvlDesc) {
			this.nextLvlDesc = nextLvlDesc;
		}
	}
	
	public PetInfoResponse(int serial, Pet pet) {
		super(serial);
		this.id = pet.getId();
		this.name = pet.getTemplate().getName();
		this.icon = pet.getTemplate().getIcon();
		this.level = pet.getLevel();
		this.exp = pet.getExp();
		this.sex = pet.getTemplate().getSex();
		this.state = (byte) pet.getState().ordinal();
		this.type = pet.getTemplate().getType();
		this.animation = pet.getTemplate().getAnimation();
		this.generation = 1;
		this.spirit = pet.getSpirit();
		this.spiritMax = pet.getTemplate().getSpirit();
		this.food = pet.getTemplate().getFood();
		this.washCD = pet.getWashCD() / 1000;
		this.playCD = pet.getPlayCD() / 1000;
		this.washCost = pet.getTemplate().getWashCost();
		List<PetSkill> pss = pet.getSkills();
		this.skills = new ArrayList<Skill>(pss.size());
		for (int i = 0, size = pss.size(); i < size; i++) {
			this.skills.add(new Skill(pss.get(i)));
		}
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public int getLevel() {
		return level;
	}

	public void setLevel(int level) {
		this.level = level;
	}

	public int getExp() {
		return exp;
	}

	public void setExp(int exp) {
		this.exp = exp;
	}

	public byte getSex() {
		return sex;
	}

	public void setSex(byte sex) {
		this.sex = sex;
	}

	public byte getState() {
		return state;
	}

	public void setState(byte state) {
		this.state = state;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getAnimation() {
		return animation;
	}

	public void setAnimation(String animation) {
		this.animation = animation;
	}

	public int getGeneration() {
		return generation;
	}

	public void setGeneration(int generation) {
		this.generation = generation;
	}

	public int getSpirit() {
		return spirit;
	}

	public void setSpirit(int spirit) {
		this.spirit = spirit;
	}

	public int getSpiritMax() {
		return spiritMax;
	}

	public void setSpiritMax(int spiritMax) {
		this.spiritMax = spiritMax;
	}

	public int getFood() {
		return food;
	}

	public void setFood(int food) {
		this.food = food;
	}

	public int getWashCD() {
		return washCD;
	}

	public void setWashCD(int washCD) {
		this.washCD = washCD;
	}

	public int getPlayCD() {
		return playCD;
	}

	public void setPlayCD(int playCD) {
		this.playCD = playCD;
	}

	public int getWashCost() {
		return washCost;
	}

	public void setWashCost(int washCost) {
		this.washCost = washCost;
	}

	public List<Skill> getSkills() {
		return skills;
	}

	public void setSkills(List<Skill> skills) {
		this.skills = skills;
	}

}
